home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
pascal
/
makescrn.zip
/
MAKESCRN.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1989-08-27
|
11KB
|
449 lines
PROGRAM MakeScreen;
{--------------------------------------------------------------------------
A text screen painting utility to facilitate creation of program screens
using the Window Library capabilities of the TurboPower Software TpCrt
unit, and to demonstrate the unit's abilities.
Copyright 1989 Steve Sneed
CIS IDs 71520,77 or 70007,3574
Released to the public domain 26-August-89
---------------------------------------------------------------------------}
USES
TpCrt, TpMouse, TpString, TpEdit;
CONST
MouseActive : Boolean = FALSE; { TRUE if mouse in use }
SSFrame : FrameArray = '┌└┐┘─│'; { single-single }
DDFrame : FrameArray = '╔╚╗╝═║'; { double-double }
DSFrame : FrameArray = '╒╘╕╛═│'; { double-single }
SDFrame : FrameArray = '╓╙╖╜─║'; { single-double }
CvtMouseSet : Array[$E9..$EF] of Word =
($011B, { used to convert mouse buttons to keys }
$011B,
$011B,
$011B,
$011B,
$011B,
$1C0D);
TYPE
MakeScrnKeyFunc = FUNCTION : Word;
ScrRecord = RECORD
Covers : Pointer;
C1,C2 : Word;
END;
VAR
MyX,MyY : Byte;
MakeScrnKey : MakeScrnKeyFunc;
ScrRec : ScrRecord;
PWP : PackedWindowPtr;
CurScrFN : String;
PROCEDURE Endit(I : Integer);
BEGIN
HideMouse;
NormalCursor;
ClrScr;
CASE I of
0 : ;
1 : WriteLn('Error allocating memory for screen');
2 : WriteLn('Error saving screen to library');
3 : WriteLn('Error reading screen from library');
else WriteLn('Unknown fatal error');
END;
Halt(I);
END;
PROCEDURE Push;
{ save the current screen, set up for a menu request }
BEGIN
if MouseActive then HideMouse;
if NOT SaveWindow(1,1,ScreenWidth,ScreenHeight,True,ScrRec.Covers) then EndIt(1);
GetCursorState(ScrRec.C1,ScrRec.C2);
HiddenCursor;
END;
PROCEDURE Pop;
{ restore the saved screen }
BEGIN
RestoreWindow(1,1,ScreenWidth,ScreenHeight,True,ScrRec.Covers);
RestoreCursorState(ScrRec.C1,ScrRec.C2);
if MouseActive then ShowMouse;
END;
PROCEDURE MoveCursor(W : Word);
BEGIN
CASE Hi(W) of
71 : GoToXY(1,1);
72 : GoToXY(WhereX,WhereY - 1);
75 : GoToXY(WhereX - 1,WhereY);
77 : GoToXY(WhereX + 1,WhereY);
79 : GoToXY(ScreenWidth,ScreenHeight);
80 : GoToXY(WhereX,WhereY + 1);
else ;
END;
END;
FUNCTION MyKey(VAR X,Y : Byte) : Word;
LABEL L01;
{ returns the keystroke and the cursor location }
VAR W : Word;
BEGIN
L01:
W := MakeScrnKey;
if (Lo(W) = 0) and (Hi(W) >= 71) and (Hi(W) <= 81) then
BEGIN
MoveCursor(W);
if MouseActive then MouseGoToXY(WhereX,WhereY);
GoTo L01;
END;
if (MouseActive) then
BEGIN
GoToXY(MouseWhereX,MouseWhereY);
if (Hi(W) >= $E9) and (Hi(W) <= $EF) then
W := CvtMouseSet[Hi(W)];
END;
X := WhereX;
Y := WhereY;
MyKey := W;
END;
FUNCTION DropAnchor(VAR TX,TY,LX,LY : Byte) : Word;
VAR C : Char;
MA : Byte;
BEGIN
MA := ReadAttrAtCursor;
C := ReadCharAtCursor;
FastWrite('*',TY,TX,MA + 128);
DropAnchor := MyKey(LX,LY);
FastWrite(C,TY,TX,MA);
END;
PROCEDURE DrawFrame;
VAR TX,TY,LX,LY,MA : Byte;
W : Word;
BEGIN
W := MyKey(TX,TY);
if Lo(W) = 27 then exit;
W := DropAnchor(TX,TY,LX,LY);
if Lo(W) = 27 then exit;
MA := ReadAttrAtCursor;
FrameWindow(TX,TY,LX,LY,MA,MA,'');
END;
PROCEDURE EraseArea;
VAR TX,TY,LX,LY : Byte;
B : Byte;
W : Word;
BEGIN
W := MyKey(TX,TY);
if Lo(W) = 27 then exit;
W := DropAnchor(TX,TY,LX,LY);
if Lo(W) = 27 then exit;
for B := TY to LY do
FastText(CharStr(' ',(LX - TX + 1)),B,TX);
END;
FUNCTION GetAttrVal(B : Byte) : Byte;
VAR X,Y,N : Byte;
S : String;
E : Boolean;
NB : Integer;
BEGIN
Push;
S := HexB(B);
FrameWindow(62,1,80,19,$1F,$1F,' Colors ');
X := 64; Y := 3;
FastWrite(' 0123456789ABCDEF',2,63,$1F);
FastVert('0123456789ABCDEF',3,63,$1F);
for N := 0 to 255 do
BEGIN
FastWrite('*',Y,X,N);
Inc(X);
if X > 79 then
BEGIN
X := 64;
Inc(Y);
END;
END;
REPEAT
NB := -1;
ReadString('New attribute: ',ScreenHeight,1,2,$1F,$1F,$1F,E,S);
S := '$' + S;
if (E) or (NOT(Str2Int(S,NB))) or (NB < 0) or (NB > 255) then
BEGIN
NB := -1;
S := HexB(B);
END;
UNTIL NB >= 0;
GetAttrVal := Byte(NB);
Pop;
END;
PROCEDURE ChangeAttrArea;
VAR TX,TY,LX,LY : Byte;
B,NB : Byte;
W : Word;
BEGIN
W := MyKey(TX,TY);
if Lo(W) = 27 then exit;
W := DropAnchor(TX,TY,LX,LY);
if Lo(W) = 27 then exit;
NB := GetAttrVal(ReadAttrAtCursor);
for B := TY to LY do
ChangeAttribute((LX - TX + 1),B,TX,NB);
END;
PROCEDURE MoveArea;
VAR SP : Pointer;
TX,TY,LX,LY : Byte;
NX,NY,B,NB,A : Byte;
W : Word;
PW : PackedWindowPtr;
S : String;
BEGIN
S := '';
W := MyKey(TX,TY);
if Lo(W) = 27 then exit;
NB := ReadAttrAtCursor;
if WhereX > 1 then
ReadAttribute(1,WhereY,WhereX - 1,S)
else if WhereY > 1 then
ReadAttribute(1,WhereY - 1,WhereX,S);
W := DropAnchor(TX,TY,LX,LY);
if (Lo(W) = 27) then exit;
if S = '' then
BEGIN
if WhereX < ScreenWidth then
ReadAttribute(1,WhereY,WhereX + 1,S)
else if WhereY < ScreenHeight then
ReadAttribute(1,WhereY + 1,WhereX,S);
END;
if S <> '' then NB := Ord(S[1]);
PW := PackWindow(TX,TY,LX,LY);
if PW = NIL then exit;
W := MyKey(NX,NY);
if Lo(W) = 27 then exit;
for B := TY to LY do
FastWrite(CharStr(' ',(LX - TX + 1)),B,TX,NB);
DispPackedWindowAt(PW,NY,NX);
END;
PROCEDURE InputText;
VAR TX,TY,LX,LY,MA : Byte;
W : Word;
BEGIN
W := MyKey(TX,TY);
if Lo(W) = 27 then exit;
if MouseActive then
BEGIN
HideMouse;
NormalCursor;
END;
REPEAT
W := MyKey(TX,TY);
CASE Lo(W) of
0 : MoveCursor(W);
8 : BEGIN
FastWrite(' ',TY,TX,ReadAttrAtCursor);
if TX > 1 then Dec(TX);
GoToXY(TX,TY);
MouseGoToXY(TX,TY);
END;
1..31 : ;
else BEGIN
FastWrite(Char(Lo(W)),TY,TX,ReadAttrAtCursor);
if TX < ScreenWidth then Inc(TX);
GoToXY(TX,TY);
MouseGoToXY(TX,TY);
END;
END;
UNTIL (Lo(W) = 27);
if MouseActive then
ShowMouse;
BlockCursor;
END;
PROCEDURE View;
VAR X,Y : Byte;
BEGIN
REPEAT UNTIL MyKey(X,Y) <> $FFFF;
END;
FUNCTION SaveThisScreen : Boolean;
VAR S : String;
E : Boolean;
BEGIN
SaveThisScreen := FALSE;
Push;
PWP := PackWindow(1,1,ScreenWidth,ScreenHeight);
if PWP = NIL then
BEGIN
Pop;
exit;
END;
S := '';
ReadString('Filename for this screen: ',ScreenHeight,1,12,$1F,$1F,$1F,E,S);
if S = '' then
BEGIN
Pop;
exit;
END;
CurScrFN := StUpcase(S);
WritePackedWindow(PWP,S);
SaveThisScreen := (CrtError = 0);
Pop;
END;
FUNCTION LoadThisScreen(UseCurScrFN : Boolean) : Boolean;
VAR S : String;
E : Boolean;
BEGIN
LoadThisScreen := FALSE;
if NOT UseCurScrFN then
BEGIN
Push;
S := '';
ReadString('Screen file to read: ',ScreenHeight,1,12,$1F,$1F,$1F,E,S);
if S = '' then
BEGIN
Pop;
exit;
END;
CurScrFN := StUpCase(S);
Pop;
END;
PWP := ReadPackedWindow(CurScrFN);
if PWP = NIL then exit;
DispPackedWindow(PWP);
LoadThisScreen := True;
END;
PROCEDURE NewFrameSet;
VAR I : Integer;
E : Boolean;
S : String[6];
BEGIN
Push;
S := ' ';
Move(FrameChars[ULeft],S[1],6);
FrameWindow(72,1,80,6,$1F,$1F,'');
FastVert('1234',2,73,$1F);
Move(SSFrame[ULeft],S[1],6);
FastWrite(S,2,74,$1F);
Move(DDFrame[ULeft],S[1],6);
FastWrite(S,3,74,$1F);
Move(DSFrame[ULeft],S[1],6);
FastWrite(S,4,74,$1F);
Move(SDFrame[ULeft],S[1],6);
FastWrite(S,5,74,$1F);
I := 3;
ReadInteger('New frame set (1 - 4): ',ScreenHeight,1,1,$1F,$1F,1,4,E,I);
CASE I of
1 : FrameChars := SSFrame;
2 : FrameChars := DDFrame;
3 : FrameChars := DSFrame;
4 : FrameChars := SDFrame;
END;
Pop;
END;
FUNCTION Menu : Char;
VAR I : Integer;
W : Word;
BEGIN
HiddenCursor;
if MouseActive then HideMouse;
Push;
FrameWindow(58,1,80,12,$1F,$1F,' MakeScreen Menu ');
For I := 2 to 11 do FastWrite(CharStr(' ',21),I,59,$1F);
FastWrite('Change attributes',2,60,$17);
FastWrite('Draw frame',3,60,$17);
FastWrite('Erase area',4,60,$17);
FastWrite('Frame chars change',5,60,$17);
FastWrite('Input text',6,60,$17);
FastWrite('Load from Library',7,60,$17);
FastWrite('Move region',8,60,$17);
FastWrite('Save to Library',9,60,$17);
FastWrite('View screen',10,60,$17);
FastWrite('Quit',11,60,$17);
For I := 2 to 11 do ChangeAttribute(1,I,60,$1F);
REPEAT
W := ReadKeyWord;
UNTIL Upcase(Chr(Lo(W))) in ['C','D','E','F','I','L','M','Q','S','V'];
Menu := Upcase(Chr(Lo(W)));
Pop;
if MouseActive then ShowMouse;
BlockCursor;
END;
PROCEDURE InitMakeScreen;
BEGIN
ClrScr;
FrameChars := DSFrame;
if ParamCount = 0 then CurScrFN := '' else
BEGIN
CurScrFN := StUpCase(ParamStr(1));
if NOT LoadThisScreen(TRUE) then EndIt(2);
END;
BlockCursor;
if MouseInstalled then
BEGIN
MouseActive := TRUE;
MakeScrnKey := ReadKeyOrButton;
EnableEventHandling;
BlockMouseCursor;
ShowMouse;
END
else MakeScrnKey := ReadKeyWord;
END;
PROCEDURE MakeTheScreen;
VAR C : Char;
BEGIN
InitMakeScreen;
REPEAT
C := Menu;
CASE C of
'Q': EndIt(0);
'C': ChangeAttrArea;
'I': InputText;
'D': DrawFrame;
'E': EraseArea;
'F': NewFrameSet;
'M': MoveArea;
'V': View;
'S': if NOT SaveThisScreen then EndIt(2);
'L': if NOT LoadThisScreen(FALSE) then EndIt(3);
else ;
END;
UNTIL False;
END;
BEGIN
MakeTheScreen;
END.